/*******************************************************************************/
/*    FILE: pi_error.h      AUTHOR: John Sirett (johnsirett3@googlemail.com)
/*    -------------------------------------------------------------
/*    LAYER 0:    Platform Independence Layer
/*    IMPORTANCE: CRITICAL
/*
/*    Error handling, debug message systems, assertions & other code that forms
/*    an all-purpose safety net.
/*
/*******************************************************************************/
#ifndef _PI_ERROR_H
#define _PI_ERROR_H

#include <string>
#include <sstream>

#ifdef _WIN32
#include <windows.h>
static inline void DebugMessage(std::string message) {
	MessageBoxEx(0, message.c_str(), "Debug Message", 0, 0);
}
static inline void ErrorMessage(std::string message) {
	MessageBoxEx(0, message.c_str(),"Fatal Error",0,0);
}
#else
#include <iostream>
static inline void DebugMessage(std::string message) {
	std::cout << message;
}
static inline void ErrorMessage(std::string message) {
	std::cerr << message;
}
#endif

static inline void GraciousAssertionFailure(std::string expr, std::string file, int line) {
	std::ostringstream ss("");
	ss << "FATAL: Assertion \"" << expr << "\" did not hold true @ Line " << line << ", " << file << std::endl;
	ErrorMessage(ss.str());

	exit(-1);
}

#ifndef _FINAL // Enable assertions in all but 'Production' build.
#define _ENABLE_ASSERTIONS
#endif

#ifdef _ENABLE_ASSERTIONS
#define ASSERT(expr) \
if (expr) {} \
 else { \
	 GraciousAssertionFailure(#expr, __FILE__, __LINE__); \
 }
#else
// Do nothing, as the assertion is assumed to be true.
#define ASSERT(expr)
#endif

#endif // _PI_ERROR_H